<template>
	<view class="box-project-container">
		<view class="top-box">
			<navBar title="基地选择"  @goBack="goBack"></navBar>
			<view class="container-search">
				<u-search class="search-input" placeholder="请输入关键字" @clear="clearCondition" v-model="searchText" :showAction="false"  @search="queryByCondition" @change="queryByCondition"></u-search>
				<scroll-view scroll-y="true" class="scroll-box"
					:style="{height:`calc(100vh - ${boxHeight.navBarH + boxHeight.viewH + 20}px)`}">
						<view class="data-box" v-for="item in mockData" :key="item.id">
							<view @click="selectedItem(item)">{{ item.name }}</view>
						</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getStationList } from "@/api/baseManage/baseManage.js"
	export default {
		name:'regularStation',
		data() {
			return {
				// 几个盒子的高度,计算scroll-view的高度
				boxHeight: {
					navBarH: 40,
					viewH: 20,
				},
				searchText:null,
				type:0,
				mockData:[]
			}
		},
		onLoad(param) {
			const eventChannel = this.getOpenerEventChannel();
			this.eventChannel = eventChannel
		},
		mounted() {
			// 计算scorll-view的高度 , 用100vh减去几个不滚动盒子的高度
			const query = uni.createSelectorQuery().in(this);
			query.select('.u-navbar .u-navbar--fixed').boundingClientRect(data => {
				this.boxHeight.navBarH = data.height
			}).exec();
			query.select('.search-input').boundingClientRect(data => {
				this.boxHeight.viewH = data.height
			}).exec();
			this.getData()
		},
		methods: {
			goBack(){
				uni.navigateBack()
			},
			getData(name = null) {
				let resq = {
					typeIds:[102,104],
					name:this.searchText,
					projectId:null
				}
				getStationList(resq).then(res => {
					if(!res.success) return
					this.mockData = res.result
				})
			},
			selectedItem(item) {
				uni.navigateBack({
					success: () => {
						this.eventChannel.emit("setData", {
							data: item
						})
					}
				});
			},
			/**
			 * @param {String} val 失焦后的值
			 * @param {String} type 当前tab
			 */
			queryByCondition(val) {
				this.getData(val)
			},
			clearCondition(type){
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box-project-container {
		height: 100vh;
		/* #ifdef MP-WEIXIN */
			padding-top: 200rpx;
		/* #endif */
		.container-search {
			
			padding: 0 30rpx;
			.search-input {
				margin: 20rpx 0 !important;
			}
			.data-box {
				padding: 30rpx 0;
				border-bottom: 4rpx solid #f4f6f9;
				font-size: 32rpx;
			}
			.data-box:last-child {
				border-bottom: none;
			}
		}
	}
	/deep/ .u-search__content {
		height:88rpx
	}
</style>